
#include "EquationSolver.hpp"

const double pi=acos(-1);

// implement the funciton of derived class function1.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function1:public Function{
public:
    double operator()(const double &x) const {
        return (89*sin(pi*11.5/180)*sin(x)*cos(x)+89*cos(pi*11.5/180)*sin(x)*sin(x)-(76.5*sin(pi*11.5/180)-27.5*tan(pi*11.5/180))*cos(x)-(76.5*cos(pi*11.5/180)-27.5)*sin(x));
    }
    void sol1()
    {
        Newton solver1((*this),pi/6,1000);
        std::cout<<"(I) Verifying whether alpha approximately equals to 33 degrees or not. "<<std::endl;
        solver1.solve();
        std::cout<<"In fact pi*33/180≈0.575958653158. Thus the result is convincing."<<std::endl;
        std::cout<<std::endl;
    }
}f1;

// implement the funciton of derived class function2.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function2:public Function{
public:
    double operator()(const double &x) const {
        return (89*sin(pi*11.5/180)*sin(x)*cos(x)+89*cos(pi*11.5/180)*sin(x)*sin(x)-(64*sin(pi*11.5/180)-15*tan(pi*11.5/180))*cos(x)-(64*cos(pi*11.5/180)-15)*sin(x));
    }
    void sol2()
    {
        Newton solver2((*this),pi*33/180,999);
        std::cout<<"(II) x0≈33 degrees. ";
        solver2.solve();
        std::cout<<std::endl;
    }
}f2;

// implement the funciton of derived class function3.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function3:public Function{
public:
    double operator()(const double &x) const {
        return (89*sin(pi*11.5/180)*sin(x)*cos(x)+89*cos(pi*11.5/180)*sin(x)*sin(x)-(76.5*sin(pi*11.5/180)-27.5*tan(pi*11.5/180))*cos(x)-(76.5*cos(pi*11.5/180)-27.5)*sin(x));
    }
    void sol3()
    {
        Secant solver3((*this),0.0,pi/3,_eps,1000);
        std::cout<<"(III) x0=0, x1=pi/3. ";
        solver3.solve();
        std::cout<<std::endl;
    }
}f3;

int main()
{
    std::cout<<"The Assignment F tests on Asinxcosx+B(sinx)^2-Ccosx-Esinx=0."<<std::endl<<"The unit is omitted here for convenience of writing."<<std::endl<<std::endl;
    f1.sol1();
    f2.sol2();
    f3.sol3();
    std::cout<<"--------------------Test succeeds.--------------------"<<std::endl<<std::endl;
    return 0;
}

